<?php

namespace App\Admin\Grid\Displayers;

use App\Admin\Grid;
use App\Admin\Grid\Column;

abstract class AbstractDisplayer
{
    /**
     * Grid表格实例
     *
     * @var Grid
     */
    protected $grid;

    /**
     * Column列实例
     *
     * @var Column
     */
    protected $column;

    /**
     * @var \stdClass
     */
    public $row;

    /**
     * 要被处理的值
     *
     * @var mixed
     */
    protected $value;

    /**
     * AbstractDisplayer constructor.
     * @param mixed     $value
     * @param Grid      $grid
     * @param Column    $column
     * @param \stdClass $row
     */
    public function __construct($value, Grid $grid, Column $column, \stdClass $row)
    {
        $this->value = $value;
        $this->grid = $grid;
        $this->column = $column;
        $this->row = $row;
    }

    /**
     * 获取当前行的数据库表主键名
     *
     * @return mixed
     */
    public function getKey()
    {
        return $this->row->{$this->grid->getKeyName()};
    }

    /**
     * 获取当前资源的url路径
     *
     * @return mixed
     */
    public function getResource()
    {
        return $this->grid->resource();
    }

    /**
     * 显示数据前的回调,用于处理显示的数据
     *
     * @return mixed
     */
    abstract public function display();
}